# src/plot_chain.py
import json, matplotlib.pyplot as plt, seaborn as sns, pathlib, datetime

data_file = pathlib.Path(__file__).parent.parent / "data" / "chain.json"
chain = json.loads(data_file.read_text())

indexes = [b["index"] for b in chain]
timestamps = [b["timestamp"] for b in chain]

plt.figure(figsize=(6,3))
sns.lineplot(x=indexes, y=timestamps, marker='o')
plt.title("Blockchain Growth Over Time")
plt.xlabel("Block Index")
plt.ylabel("Unix Timestamp")
plt.tight_layout()
out_png = pathlib.Path(__file__).parent.parent / "docs" / "fig_growth.png"
out_png.parent.mkdir(exist_ok=True)
plt.savefig(out_png, dpi=300)
print(f"图已保存到 {out_png}")
